#include "BinarySearch.h"

int BinarySerach_Recursive(int * array, int lower, int upper, int key)
{
	if(upper < lower)
		return -1;
	else
	{
		int middle = lower + (upper - lower)/2;

		if(array[middle] > key)
			return BinarySerach_Recursive(array, lower, middle-1, key);
		else if(array[middle] < key)
			return BinarySerach_Recursive(array, middle+1, upper, key);
		else
			return middle;
	}
}

int BinarySerach_Iterative(int * array, int lower, int upper, int key)
{
	int middle;
	while (upper >= lower)
	{
		middle = lower + (upper - lower)/2;

		if(array[middle] > key)
			upper = middle-1;
		else if(array[middle] < key)
			lower = middle+1;
		else
			return middle;
	}
	return -1;
}